package com.lanou.moving.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.lanou.moving.R;
import com.lanou.moving.entity.SearchSongEntity;

import java.util.ArrayList;

/**
 * Created by dllo on 15/11/2.
 */
public class SearchListViewAdapter extends BaseAdapter {
    private Context context;
    private ArrayList<SearchSongEntity> data;
    public SearchListViewAdapter(Context context, ArrayList<SearchSongEntity> data) {
        this.context = context;
        this.data = data;
    }


    @Override
    public int getCount() {
        if (data != null && data.size() > 0)
            return data.size();
        else
            return 0;
    }

    @Override
    public Object getItem(int position) {
        if (data != null && data.size() > 0)
            return data.get(position);
        else
            return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_search_song, null);
            //初始化
            holder = new ViewHolder();
            holder.searchsongname = (TextView) convertView.findViewById(R.id.searchsongname);

            convertView.setTag(holder);


        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        SearchSongEntity songListResult = (SearchSongEntity) getItem(position);
        if (songListResult != null) {
            holder.searchsongname.setText(songListResult.getSongname() + "-" + songListResult.getArtistname() );
        }
        ListView songSearchLV = new ListView(context);
        songSearchLV.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            }
        });


        return convertView;
    }

    private class ViewHolder {
        private TextView searchsongname;//歌名
    }

}
